package com.neusoft.elmboot.mapper;

import java.util.List;

import com.neusoft.elmboot.po.OrderDetailet;
import lombok.Data;
import org.apache.ibatis.annotations.*;

import com.neusoft.elmboot.po.Orders;

@Mapper
public interface OrdersMapper {

	@Insert("insert into orders(userId,businessId,orderDate,orderTotal,daId,orderState) values(#{userId},#{businessId},#{orderDate},#{orderTotal},#{daId},0)")
	@Options(useGeneratedKeys=true,keyProperty="orderId",keyColumn="orderId")
    int saveOrders(Orders orders);

	@Select("select * from orders where orderId=#{orderId}")
	Orders getOrdersById(Integer orderId);

	@Select("select * from orders where userId=#{userId} order by orderId")
	List<Orders> listOrdersByUserId(String userId);

	@Update("update orders set orderState = #{state} where orderId = #{orderId}")
	void updateOrderState(Integer state, Integer orderId);

	@Select("select * from orders where businessId = #{businessId}")
    List<Orders> listOrdersByBusinessId(String businessId);

	@Select("select * from orderdetailet where orderId = #{orderId}")
	List<OrderDetailet> getOrderDetailetByOrderId(Integer orderId);

	@Delete("delete from orders where orderId = #{orderId}")
    void delOrderById(Integer orderId);

	@Select("select orderId from orders where userId = #{userId} and businessId = #{businessId} and orderDate = #{orderDate}")
    Integer getOrderId(String userId, String businessId, String orderDate);
}
